/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.slice.banner;

import ohos.aafwk.content.Intent;
import ohos.agp.components.ListContainer;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;

import com.xuexiang.xui_lib.component.banner.BannerLayout;
import com.xuexiang.xui_lib.util.Log;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;

import java.util.ArrayList;

/**
 * 使用RecycleView实现的Banner
 *
 * @since 2021-04-16
 */
@Page(name = "使用RecycleView实现的Banner", action = "RecycleViewBannerSlice", ability = BannerAbility.class)
public class RecycleViewBannerSlice extends BasePageAbilitySlice implements BannerLayout.OnBannerItemClickListener {
    private BannerLayout blHorizontal;
    private BannerLayout blVerticall;
    private RecyclerViewBannerAdapter mAdapterHorizontal;
    private RecyclerViewBannerAdapter mAdapterVertical;
    ArrayList<Integer> list;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_recycleview_banner;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        findView();
        initData();
    }

    private void findView() {
        blHorizontal = findCastComponentById(ResourceTable.Id_bl_horizontal);
        blVerticall = findCastComponentById(ResourceTable.Id_bl_vertical);
//        mAdapterHorizontal.setOnBannerItemClickListener(this);
//        mAdapterVertical.setOnBannerItemClickListener(this);
    }

    private void initData() {
        list = new ArrayList<>();
        list.add(ResourceTable.Media_banner1);
        list.add(ResourceTable.Media_banner2);
        list.add(ResourceTable.Media_banner3);
        list.add(ResourceTable.Media_banner4);
        list.add(ResourceTable.Media_banner5);
//        list.add("http://photocdn.sohu.com/tvmobilemvms/20150907/144160323071011277.jpg");
//        list.add("http://photocdn.sohu.com/tvmobilemvms/20150907/144158380433341332.jpg");
//        list.add("http://photocdn.sohu.com/tvmobilemvms/20150907/144160286644953923.jpg");
//        list.add("http://photocdn.sohu.com/tvmobilemvms/20150902/144115156939164801.jpg");
//        list.add("http://photocdn.sohu.com/tvmobilemvms/20150907/144159406950245847.jpg");

        mAdapterHorizontal = new RecyclerViewBannerAdapter(this, list);
        mAdapterVertical = new RecyclerViewBannerAdapter(this, list);
        Log.i("Banner", " adapter is empty:" + (mAdapterHorizontal == null));
        blHorizontal.setAdapter(mAdapterHorizontal);
        blVerticall.setAdapter(mAdapterVertical);
        blVerticall.setAutoPlaying(true);
        blVerticall.setAutoPlaying(true);
    }


    @Override
    public void onItemClick(int position) {
//        XToast.custom(getContext(),"你点击了第"+(position+1)+"个",20);
        Log.i("Banner", "你点击了第" + (position + 1) + "个");
    }
}
